//
//  SISSUploadBuyHouseQualificationViewController.m
//  SISSAPP
//
//  Created by 袁应荣 on 2019/7/5.
//  Copyright © 2019 优房网. All rights reserved.
//

#import "SISSUploadBuyHouseQualificationViewController.h"
#import "SISSNetworkingManager+PassengerProgress.h"
#import "SISSPassengerProgressModel.h"
#import "SISSPassengerProgressRecordInfoModel.h"
#import "SISSBuyHouseQualificationModel.h"

@interface SISSUploadBuyHouseQualificationViewController ()

@end

@implementation SISSUploadBuyHouseQualificationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.title = @"购房资格审核信息表";
    self.uploadImageView.titleStr = @"购房资格审核信息表电子档图片";
    if (self.buyHouseQualificationModel) {
        self.uploadImageView.imageUrlArr = self.buyHouseQualificationModel.image.mutableCopy;
        self.remarkView.rightTextField.text = self.buyHouseQualificationModel.otherdesc;
    }
}

- (void)confirmButtonClickAction {
    
    if (!self.buyHouseQualificationModel && (!self.uploadImageView.images || self.uploadImageView.images.count == 0)) {
        [SISSTools showSVWithTitle:@"请选择购房资格审核信息表电子档图片"];
        return;
    }
    
    NSString *otherdesc = self.remarkView.rightTextField.text ? self.remarkView.rightTextField.text : @"";
    
    if (self.buyHouseQualificationModel) { // 修改
        NSDictionary *parameters = @{
                                     @"id" : self.buyHouseQualificationModel.ID,
                                     @"adbpId" : self.passengerProgressModel.adbpId,
                                     @"otherdesc" : otherdesc
                                     };
        [kNetworkManager updateBuyHouseQualificationWithParameters:parameters images:self.uploadImageView.images success:^(id responseObject) {
            if ([responseObject[@"code"] integerValue] == 200) {
                [self pushToSuccessViewWithPopBackClassType:SISSProgressPopBackClassTypePassenger];
            }
        } failed:^(NSError *error) {
            NSLog(@"%@",error);
        }];
    } else { // 新增
        NSString *ahbpId = self.passengerProgressRecordInfoModel.ahbpId ? self.passengerProgressRecordInfoModel.ahbpId : @"";
        
        NSDictionary *parameters = @{
                                     @"ahbpId" : ahbpId,
                                     @"adbpId" : self.passengerProgressModel.adbpId,
                                     @"demand_type" : @(self.passengerProgressModel.demandType),
                                     @"otherdesc" : otherdesc
                                     };
        [kNetworkManager insertBuyHouseQualificationWithParameters:parameters images:self.uploadImageView.images success:^(id responseObject) {
            
            if ([responseObject[@"code"] integerValue] == 200) {
                [self pushToSuccessViewWithPopBackClassType:SISSProgressPopBackClassTypePassenger];
            }
            
        } failed:^(NSError *error) {
            NSLog(@"%@",error);
        }];
    }
    
}

@end
